#!/bin/sh

export DEBIAN_PRIORITY=critical

apt-get install unzip 
getnewbundle=$1
if [ "x$getnewbundle" != "x" ] ; then
        filetoget=`wget -O - http://smartcard20.com/static/install-media-bundle-and-images/install-media-bundle-public-sc20-latest.txt`
        wget --limit-rate=1m http://smartcard20.com/static/install-media-bundle-and-images/${filetoget}
        unzip ${filetoget}

        installmediadundledirname=`find . -type d -name 'install-media-bundle-*'`

        if [ "x$installmediadundledirname" == "x" ] ; then
                echo "could not find the install-media-bundle- dir"
                exit
        else
                cd ${installmediadundledirname}
        fi
else

        inimbdir=`pwd | grep install-media-bundle-`

        if [ "x$inimbdir" == "x" ] ; then
                echo "you need to execute $0 while standing in the install-media-bundle directory"
                exit
        else
                cd ${inimbdir}
        fi
fi

apt-get -y install screen sudo bzip2 unzip mysql-server expect apache2

apt-get -y purge nfs-common portmap

perl -pi -e 's/debian/smartcard20.demo/gio' /etc/hosts
perl -pi -e 's/debian/smartcard20.demo/gio' /etc/hostname
hostname smartcard20.demo

useradd --create-home --shell /bin/bash --password YG30h0h7gzH5M sc20

./unpack-media-bundle-files.sh

mkdir -p /var/cache/jboss4/tmp
chown jboss /var/cache/jboss4/tmp
mkdir -p /var/log/jboss4/
chown jboss /var/log/jboss4/
mkdir -p /var/run/jboss4/
chown jboss /var/run/jboss4/

mkdir -p /srv/www/htdocs/crl
chown jboss /srv/www/htdocs/crl

echo  "sc20    ALL=(ALL) ALL" >> /etc/sudoers


